//
//  GameScreen.m
//  iSudoku
//
//  Created by Tri Vo on 5/22/13.
//  Copyright (c) 2013 Tri Vo. All rights reserved.
//

#import "GameScreen.h"
#import "GameUtils.h"

@implementation GameScreen

+ (id)scene {
    CCScene *scene = [CCScene node];
    GameScreen *gameScreen = [GameScreen node];
    [scene addChild:gameScreen];
    return scene;
}

- (id)init {
    self = [super init];
    if (self) {
        timeBegin = 0;
        [[CTimer getInstance] resetTime];
        [self initScreen];
        [self scheduleUpdate];
    }
    return self;
}

#pragma mark - Screen Methods

- (void) initScreen {
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    
    CCMenuItemFont *back = [CCMenuItemFont itemWithString:@"Back" target:self selector:@selector(goBack)];
    
    CCMenu *menu = [CCMenu menuWithItems:back, nil];
    [menu alignItemsVerticallyWithPadding:10];
    [menu setPosition:ccp(winSize.width/2, winSize.height/2)];
    [self addChild:menu];
    
    _lblTime = [CCLabelTTF labelWithString:[[CTimer getInstance] getTime] fontName:[[GameUtils getInstance] getSystemFontName] fontSize:24];
    [_lblTime setPosition:ccp(winSize.width/2, winSize.height/2 - 60)];
    [self addChild:_lblTime];
}

- (void) goBack {
    [[CCDirector sharedDirector] popSceneWithTransition:[CCTransitionSlideInL class] withTime:0.5f];
}

- (void)update:(ccTime)delta {
    [self updateTime:delta];
}

- (void) updateTime:(ccTime)delta {
    timeBegin += delta;
    [[CTimer getInstance] increaseTime:delta];
    [_lblTime setString:[[CTimer getInstance] getTime]];
}

@end
